package com.lc.cehui.ui.fragment.home;

import android.widget.ImageView;

import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lc.cehui.R;
import com.lc.cehui.app.AppFragment;
import com.lc.cehui.http.glide.GlideApp;
import com.lc.cehui.http.response.CompanyInfoBean;
import com.lc.cehui.http.response.CompanyMeetShowBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.ui.activity.home.ExhibitionDetailsActivity;
import com.lc.cehui.util.SPUtil;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class ExhibitionatlasFragment extends AppFragment<ExhibitionDetailsActivity> {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseQuickAdapter<CompanyMeetShowBean.DataBean.PicarrBean, BaseViewHolder> adapter;
    private CompanyMeetShowBean data;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_exhibitionatlas;
    }

    @Override
    protected void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new BaseQuickAdapter<CompanyMeetShowBean.DataBean.PicarrBean, BaseViewHolder>(R.layout.item_atlas) {
                @Override
                protected void convert(@NonNull BaseViewHolder baseViewHolder, CompanyMeetShowBean.DataBean.PicarrBean dataBean) {
                    GlideApp.with(ExhibitionatlasFragment.this).load(data.getData().getCompany_picurl()).apply(new RequestOptions().placeholder(R.mipmap.logo_qyzp).error(R.mipmap.logo_qyzp)).into((ImageView)baseViewHolder.getView(R.id.img));
                }
        };
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        Gson gson = new Gson();
//                将存储的数据转成实体类
        data = gson.fromJson(SPUtil.get(getContext(), IntentKey.TEXT,""), new TypeToken<CompanyMeetShowBean>() {
        }.getType());
        adapter.setNewData(data.getData().getPicarr());
        adapter.notifyDataSetChanged();

    }
}
